package com.sgb.kjwl.view.ui.adapter.self.order;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.user.GoodsItemEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.StringUtil;

import java.util.List;

/**
 * 单条订单
 */
public class OrderItemAdapter extends BaseRecycleAdapter<GoodsItemEntity> {

    private final Context context;

    public OrderItemAdapter(Context context, List<GoodsItemEntity> data) {
        super(context, R.layout.item_order_pay_error, data);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, final GoodsItemEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        ImageView icon = holder.itemView.findViewById(R.id.iv_item);
        Glide.with(context).load(entity.getImage()).into(icon);

        TextView tvPrice = holder.itemView.findViewById(R.id.tv_price);
        tvPrice.setText("￥" + StringUtil.showPrice(entity.getUnitPrice()) + entity.getUnit());

        TextView tvCount = holder.itemView.findViewById(R.id.tv_count);
        tvCount.setText("X" + entity.getTotal());
    }
}
